package com.start.cms.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.start.cms.entity.StartCmsSpecialContentEntity;
import com.start.cms.entity.StartCmsSpecialEntity;
import com.start.cms.mappers.StartCmsSpecialContentMapper;
import com.start.cms.mappers.StartCmsSpecialMapper;
import com.start.cms.model.StartSpecialContentModel;
import com.start.cms.service.StartCmsSpecialService;
import com.start.common.entity.StartBaseEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StartCmsSpecialServiceImpl extends ServiceImpl<StartCmsSpecialMapper, StartCmsSpecialEntity> implements StartCmsSpecialService {


    @Autowired
    private StartCmsSpecialContentMapper startCmsSpecialContentMapper;

    @Override
    public StartCmsSpecialEntity getByCode(String specialCode) {
        LambdaQueryWrapper<StartCmsSpecialEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StartCmsSpecialEntity::getSpecialCode, specialCode);
        queryWrapper.orderByDesc(StartBaseEntity::getCreateTime);
        queryWrapper.last(" limit 1");
        return getOne(queryWrapper);
    }

    @Override
    public StartSpecialContentModel getSpecialContentBySpecialCode(String specialCode) {
        if (StringUtils.isEmpty(specialCode)) return null;
        final StartCmsSpecialEntity specialEntity = getByCode(specialCode);
        if (specialEntity == null) {
            return null;
        }
        final StartSpecialContentModel startSpecialContentModel = StartSpecialContentModel.create(specialEntity);
        LambdaQueryWrapper<StartCmsSpecialContentEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StartCmsSpecialContentEntity::getSpecialId, specialEntity.getId());
        queryWrapper.orderByAsc(StartCmsSpecialContentEntity::getSpecialContentSort);
        queryWrapper.orderByDesc(StartBaseEntity::getCreateTime);
        List<String> specialContentIds= startCmsSpecialContentMapper.getListContentIdBySpecialId(specialEntity.getId());
        switch (startSpecialContentModel.getSpecialContentType()) {
            case ARTICLE:


                break;
            case CATEGORY:

                break;
        }

        return null;
    }
}
